﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI.WebControls;
using ArtsShop.DataLayer.DataAccess;
using ArtsShop.DataLayer.DataObject;


namespace ArtsShop.BusinessLogic
{
    /// <summary>
    /// 
    /// </summary>
    public class ProductFamilyImage
    {
        #region Private Properties

        private string _imageUrl = string.Empty;
        private string _imageName = string.Empty;
        private string _alternateText = string.Empty;
        private bool _isDefault = false;
        //private ImageDirectory _directory;
        private int? _diffProductId;

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets the diff product id.
        /// </summary>
        /// <value>The diff product id.</value>
        public int? DiffProductId
        {
            get { return _diffProductId; }
            set { _diffProductId = value; }
        }

        /// <summary>
        /// Gets or sets the directory.
        /// </summary>
        /// <value>The directory.</value>
        public ImageDirectory Directory
        {
            get { return _directory; }
            set { _directory = value; }
        }

        /// <summary>
        /// Gets or sets the name of the image.
        /// </summary>
        /// <value>The name of the image.</value>
        public string ImageName
        {
            get { return _imageName; }
            set { _imageName = value; }
        }

        /// <summary>
        /// Gets or sets the image URL.
        /// </summary>
        /// <value>The image URL.</value>
        public string ImageUrl
        {
            get
            {
                return _imageUrl;
            }
            set
            {
                _imageUrl = value;
            }
        }

        /// <summary>
        /// Gets or sets the alternate text.
        /// </summary>
        /// <value>The alternate text.</value>
        public string AlternateText
        {
            get
            {
                return _alternateText;
            }
            set
            {
                _alternateText = value;
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is default.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is default; otherwise, <c>false</c>.
        /// </value>
        public bool IsDefault
        {
            get
            {
                return _isDefault;
            }
            set
            {
                _isDefault = value;
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance is empty.
        /// </summary>
        /// <value><c>true</c> if this instance is empty; otherwise, <c>false</c>.</value>
        public bool IsEmpty
        {
            get
            {
                return (string.IsNullOrEmpty(this._imageUrl) && string.IsNullOrEmpty(this._alternateText));
                    //CastingHelper.IsNullOrEmpty(this._imageUrl) &&
                    //CastingHelper.IsNullOrEmpty(this._alternateText);
            }
        }

        #endregion

        #region Construction
        public ProductFamilyImage(string imageUrl, string alternateText, string imageName, ImageDirectory directory)
        {
            this._imageUrl = imageUrl;
            this._alternateText = alternateText;
            this._imageName = imageName;
            this._directory = directory;
        }
        public ProductFamilyImage(string imageUrl, string alternateText, string imageName)
        {
            this._imageUrl = imageUrl;
            this._alternateText = alternateText;
            this._imageName = imageName;

        }
        public ProductFamilyImage()
            : this(string.Empty, string.Empty, string.Empty)
        {
        }
        #endregion

        #region Public Methods
        /// <summary>
        /// Displays the product images.
        /// </summary>
        /// <param name="productImageId">The product image id.</param>
        /// <param name="productImageDataGrid">The product image data grid.</param>
        public static void DisplayProductImages(int productFamilyId, DataGrid productImageDataGrid)
        {
            DataTable productImageData = ProductFamilyDAO.retrieveProductImageData(productFamilyId);

            productImageDataGrid.DataSource = productImageData;
            productImageDataGrid.DataBind();

        }

        /// <summary>
        /// Deletes the product image.
        /// </summary>
        /// <param name="productImage">The product image.</param>
        /// <returns></returns>
        public static string DeleteProductImage(int productImage)
        {
            return ProductFamilyDAO.DeleteProductFamilyImage(productImage);
        }

        /// <summary>
        /// Updates the product image.
        /// </summary>
        /// <param name="imageObject">The image object.</param>
        /// <returns></returns>
        public static string UpdateProductImage(ProductImageObject imageObject)
        {
            return ProductFamilyDAO.UpdateProductFamilyImage(imageObject.ProductImageID, imageObject.ImageName, bool.Parse(imageObject.IsDefaultText), imageObject.DiffProductId);
        }

        /// <summary>
        /// Builds the is default data table.
        /// </summary>
        /// <returns></returns>
        public static DataTable BuildIsDefaultDataTable()
        {
            DataTable isDefaultData = new DataTable();
            isDefaultData.Columns.Add("boolValue");
            isDefaultData.Columns.Add("boolId");

            DataRow selectRow = isDefaultData.NewRow();
            selectRow["boolValue"] = "Please Select";
            selectRow["boolId"] = "-1";
            isDefaultData.Rows.Add(selectRow);

            DataRow falseRow = isDefaultData.NewRow();
            falseRow["boolValue"] = "False";
            falseRow["boolId"] = "0";
            isDefaultData.Rows.Add(falseRow);

            DataRow trueRow = isDefaultData.NewRow();
            trueRow["boolValue"] = "True";
            trueRow["boolId"] = "1";
            isDefaultData.Rows.Add(trueRow);

            return isDefaultData;
        }

        /// <summary>
        /// Displays the is default data.
        /// </summary>
        /// <param name="isDefaultDropDown">The is default drop down.</param>
        public static void DisplayIsDefaultData(DropDownList isDefaultDropDown)
        {
            isDefaultDropDown.Items.Add(new ListItem("Please Select", "-1"));
            isDefaultDropDown.Items.Add(new ListItem("False", "0"));
            isDefaultDropDown.Items.Add(new ListItem("True", "1"));
            isDefaultDropDown.DataBind();
        }

        /// <summary>
        /// Inserts the product family image data.
        /// </summary>
        /// <param name="productFamilyId">The product family id.</param>
        /// <param name="imageName">Name of the image.</param>
        /// <param name="isDefaultImage">if set to <c>true</c> [is default image].</param>
        /// <param name="diffProductId">The diff product id.</param>
        /// <returns></returns>
        public static string InsertProductFamilyImageData(int productFamilyId, string imageName, bool isDefaultImage, int? diffProductId)
        {
            return ProductFamilyDAO.CreateProductFamilyImage(productFamilyId, imageName, isDefaultImage, diffProductId);
        }
    }
}
#endregion

